<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta http-equiv="pragma" content="no-cache" />
    <meta http-equiv="Cache-Control" content="no-cache" />
    <meta http-equiv="Cache-Control" content="no-store"/>
    <meta http-equiv="Expires" content="0" />
    <link rel="shortcut icon" type="image/x-icon" th:href="@{/static/favicon.ico}">
    <title th:text="${title}"></title>
    <link rel="stylesheet" th:href="@{/static/plugins/layui/css/layui.css}">
    <link rel="stylesheet" th:href="@{/static/css/layout.css}">
    <link rel="stylesheet" th:href="@{/static/css/common.css}">
    <!--begin::页面样式 -->
    <link rel="stylesheet" type="text/css" th:each="cssPath,status:${#strings.setSplit(cssPaths,',')}" th:href="@{${cssPath}}"/>
    <!--end::页面样式 -->

</head>
<body>
<div class="container">
    <div th:replace="fragments/header :: header"></div>
    <content>
        <div th:replace="fragments/left :: left"></div>

        <div th:replace=":: right"></div>
    </content>
    <div th:replace="fragments/footer :: footer"></div>
</div>

<!--公共JS-->
<script th:src="@{/static/plugins/jquery.js}"></script>
<script th:src="@{/static/plugins/layui/layui.js}"></script>
<script th:src="@{/static/js/common.js}"></script>
<script th:inline="javascript">
    var pageAuthorize = [[${pageAuthorize}]];
    $(function(){
        var $style = $("<style></style>");
        var selector = "";
        if(pageAuthorize && pageAuthorize.length > 0){
            $.each(pageAuthorize,function(i,v){
                selector += '[auth="'+ v +'"],';
            });
        }
        if(selector){
            selector = selector.substring(0,selector.length-1);
            console.log(selector);
            $style.append(selector + '{ display:inline-block }')
            $("head").append($style);
        }
        //修改密码
        $("#changepwd").on('click',function(){
            var id = $(this).data("id");
            var ii = layer.open({
                type: 2,
                content: '/user/changepwd',
                area: ['580px', '295px'],
                btn:['修改','取消'],
                title:'修改密码',
                yes:function(layero, index){
                    var body = layer.getChildFrame('body', layero);
                    var oldpwd = body.find("#oldpwd").val();
                    var newpwd = body.find("#newpwd").val();
                    var rpwd = body.find("#rpwd").val();

                    if(!oldpwd){
                        layer.msg("请输入原始密码");
                        return;
                    }
                    if(!newpwd){
                        layer.msg("请输入新密码");
                        return;
                    }
                    if(!rpwd){
                        layer.msg("请重复新密码");
                        return;
                    }
                    if(newpwd != rpwd){
                        layer.msg("两次密码输入不一致");
                        return;
                    }
                    if (newpwd === "" || newpwd == null || newpwd.length < 6 || newpwd.length > 16) {
                        layer.msg( '密码必须是6-16位');
                        return
                    } else {
                        var pswd = /^[0-9a-zA-Z_$!?]{6,16}$/;
                        if (!pswd.test(newpwd)) {
                            layer.msg(  "您输入的密码不符合规则，请从新输入");
                            return
                        }
                    }
                    $.ajax({
                        url:"/user/change",
                        data:{oldpwd:oldpwd,newpwd:newpwd},
                        type:'post',
                        dataType:'json',
                        success:function(rs){
                            layer.msg(rs.message);
                            if(rs.code == 200){
                                layer.close(ii);
                            }
                        }
                    });
                },
                btn2:function(index){
                    layer.close(index);
                }
            });
        });
    });
</script>

<!--页面自定义JS-->
<script type="text/javascript" th:each="jsPath,status:${#strings.setSplit(jsPaths,',')}" th:src="@{${jsPath}}" ></script>
</body>
</html>